using System;
using UnityEngine;
using UnityEngine.EventSystems;

namespace HCP
{
	public static class Element
	{
		public static string ReflectProperty(Component element, string propertyName)
		{
			string result = string.Empty;
			try
			{
				result = element.GetType().GetProperty(propertyName).GetValue(element, null).ToString();
			}
			catch (Exception ex)
			{
				result = ex.ToString();
			}
			return result;
		}

		public static string ReflectMethod0(Component element, string methodName)
		{
			string result = string.Empty;
			try
			{
				result = element.GetType().GetMethod(methodName).Invoke(element, null).ToString();
			}
			catch (Exception ex)
			{
				result = ex.ToString();
			}
			return result;
		}

		public static string ConstructXPath(Component element)
		{
			string text = "/" + element.name;
			Transform parent = element.transform.parent;
			while (parent != null)
			{
				text = "/" + parent.name + text;
				parent = parent.transform.parent;
			}
			if (!(element is Transform))
			{
				text += ":";
				string name = element.GetType().Name;
				if (!name.Equals(element.name))
				{
					text += name;
				}
			}
			return text;
		}

		public static Rect ConstructScreenRect(Component element)
		{
			Vector3[] array = new Vector3[2];
			Vector3[] array2 = new Vector3[2];
			Camera cam = null;
			RectTransform component = element.GetComponent<RectTransform>();
			Renderer component2 = element.GetComponent<Renderer>();
			if (component != null)
			{
				Canvas componentInParent = element.GetComponentInParent<Canvas>();
				if (componentInParent.renderMode == RenderMode.ScreenSpaceCamera || componentInParent.renderMode == RenderMode.WorldSpace)
				{
					cam = componentInParent.worldCamera;
				}
				else
				{
					cam = null;
				}
				Vector3[] array3 = new Vector3[4];
				component.GetWorldCorners(array3);
				array2[0] = array3[1];
				array2[1] = array3[3];
			}
			else if (component2)
			{
				array2[0] = component2.bounds.min;
				array2[1] = component2.bounds.max;
			}
			else
			{
				array2[0] = element.transform.position;
				array2[1] = element.transform.position;
			}
			array[0] = RectTransformUtility.WorldToScreenPoint(cam, array2[0]);
			array[1] = RectTransformUtility.WorldToScreenPoint(cam, array2[1]);
			array[0].y = (float)Screen.height - array[0].y;
			array[1].y = (float)Screen.height - array[1].y;
			return new Rect(array[0], array[1] - array[0]);
		}

		public static string GetName(Component element)
		{
			return element.GetType().Name;
		}

		public static string GetClassName(Component element)
		{
			return element.GetType().FullName;
		}

		public static bool DetermineDisplayed(Component element)
		{
			Rect rect = Element.ConstructScreenRect(element);
			return rect.y >= 0f && rect.y + rect.height <= (float)Screen.height && rect.x >= 0f && rect.x + rect.width <= (float)Screen.width && element.gameObject.activeInHierarchy;
		}

		public static bool GetEnabled(Component element)
		{
			Behaviour behaviour = element as Behaviour;
			return behaviour == null || behaviour.enabled;
		}

		public static bool GetSelected(Component element)
		{
			return element.gameObject == EventSystem.current.currentSelectedGameObject;
		}
	}
}
